<template>
  <h1>登录</h1>
  <el-icon :size="20">
    <Edit />
  </el-icon>
  <Edit style="width: 1em; height: 1em; margin-right: 8px" />
  <el-card>
    <!-- 表单组件 -->
    <el-form
      ref="form"
      :model="userInfo"
      status-icon
      label-width="120px"
      class="demo-ruleForm"
      :rules="rules"
    >
      <!--  用户名 -->
      <el-form-item label="用户名" prop="userName">
        <el-input v-model="userName" type="text" />
      </el-form-item>
      <!-- 用户密码 -->
      <el-form-item label="Password" prop="passWord">
        <el-input v-model="passWord" type="password" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm"> Submit </el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script>
import { ElMessage } from "element-plus";
import axios from "../../utils/axios";
export default {
  data() {
    return {
      userName: "",
      passWord: "",
    };
  },
  methods: {
    async submitForm() {
      const res = await axios.post("v1/user/login", {
        us: this.userName,
        ps: this.passWord,
      });
      console.log(res);
      if (res.err == 0) {
        console.log(res.info);
        localStorage.setItem("info", JSON.stringify(res.info));
        this.$router.replace("/home");
      }
      return;
    },
  },
};
</script>
